<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="9" :lg="9" :md="9" :sm="24">
            <a-form-item label="数据日期">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.bsjrq" ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.esjrq"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="报表名称">
              <j-search-select-tag
                placeholder="请选择报表名称"
                v-model="queryParam.reporttypecode"
                dict="llbb_report_forms,reporttypename,reporttypecode"
                :pageSize="null">
              </j-search-select-tag>
            </a-form-item>
          </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="币种">
               <j-tree-select
                ref="treeSelect"
                placeholder="请选择币种"
                v-model="queryParam.bz"
                dict="llbb_param_config,name,code"
                pidValue="1382973175608823809"
                hasChildField="has_child"
                >
              </j-tree-select>
              </a-form-item>
            </a-col>
          <template v-if="toggleSearchStatus">
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="exportXlsx()">导出</a-button>
      <a-button type="primary" @click="syncData" icon="sync" style="margin-left: 8px">更新数据</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
        <a @click="handleDetail(record)">详情</a>
        </span>

      </a-table>
    </div>

    <llbb-modal ref="modalForm" @ok="modalFormOk"></llbb-modal>
    <SjrqModal ref="SjrqModal" :loading="rqloading"></SjrqModal>
  </a-card>
</template>

<script>
  import { downFile,postAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LlbbModal from './modules/LlbbModal'
  import SjrqModal from '../common/sjrq/SjrqModal'

  export default {
    name: 'LlbbList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      SjrqModal,
      LlbbModal
    },
    data () {
      return {
        rqloading: false,
        description: '业务余额核对管理页面',
        // 表头
        columns: [
          {
            title:'数据日期',
            align:"center",
            dataIndex: 'sjrq',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'报表名称',
            align:"center",
            dataIndex: 'reporttypename'
          },
          {
            title:'科目',
            align:"center",
            dataIndex: 'km'
          },
          {
            title:'币种',
            align:"center",
            dataIndex: 'bz'
          },
          {
            title:'全量余额(元)',
            align:"center",
            dataIndex: 'qlje'
          },
          {
            title:'全量笔数',
            align:"center",
            dataIndex: 'qlbs'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createtime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'更新时间',
            align:"center",
            dataIndex: 'updatetime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'操作人',
            align:"center",
            dataIndex: 'updateby'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/llbb/llbb/listInfo",
          delete: "/llbb/llbb/delete",
          deleteBatch: "/llbb/llbb/deleteBatch",
          exportXlsUrl: "/llbb/llbb/exportInfoXls",
          importExcelUrl: "llbb/llbb/importExcel",
          syncUrl: "/llbb/llbb/spllbb"
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'sjts',text:'sjts'})
        fieldList.push({type:'date',value:'createTime',text:'createTime'})
        fieldList.push({type:'date',value:'updateTime',text:'updateTime'})
        fieldList.push({type:'string',value:'updateBy',text:'updateBy'})
        fieldList.push({type:'date',value:'sjrq',text:'sjrq'})
        fieldList.push({type:'string',value:'tbname',text:'tbname'})
        fieldList.push({type:'string',value:'km',text:'km'})
        fieldList.push({type:'string',value:'bz',text:'bz'})
        fieldList.push({type:'number',value:'je',text:'je'})
        fieldList.push({type:'number',value:'zz',text:'zz'})
        fieldList.push({type:'number',value:'ce',text:'JE-ZZ'})
        this.superFieldList = fieldList
      },
      exportXlsx: function(){
        var fileName='业务余额核对';
        let param = this.getQueryParams();
        if(this.selectedRowKeys && this.selectedRowKeys.length>0){
          param['selections'] = this.selectedRowKeys.join(",")
        }
        console.log("导出参数",param)
        let downloadUrl = this.url.exportXlsUrl;
        downFile(downloadUrl,param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xlsx')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xlsx')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      syncData: function(){
        this.$refs.SjrqModal.showModal("sync");
      },
      sync: function (sjrq) {
        var param={"indate":sjrq};
        this.rqloading = true
        postAction(this.url.syncUrl+"?indate="+sjrq, param).then((res) => {
          this.rqloading = false
          if(res.success){
            this.$message.success(res.result)
            this.visible=false
            this.$emit('ok')
          }else{
            this.$message.warning(res.result)
          }
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>